import json

import requests


class RequestsHandler:
    def __init__(self, session):
        self.session = session

    def get_request(self, url, body=None, headers=None):
        response = None
        try:
            if body is None:
                response = self.session.request(method="get", url=url).json()
                # response = self.session(method="get", url=url, cookies=self.session).json()
            else:
                response = self.session.request(method="get", url=url).json()
                # response = self.session(method="get", url=url, param=body).json()
        except requests.RequestException as e:
            print(e)
            response = None
        return response

    def post_request(self, url, body, headers):

        try:
            if body is None:
                response = requests.post(url=url, headers=headers).json()
            else:
                response = self.session.request(method="post", url=url, data=json.dumps(body), headers=headers).json()
        except requests.RequestException as e:
            print(e)
            return None

        except Exception as e:
            print(e)
            return None

        out_param = response
        globals()["out_param"] = out_param
        return self.session
